package com.mail.server.service;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mail.dubbo.api.SmsFlashPromotionApi;
import com.mail.model.db.SmsFlashPromotion;
import com.mail.model.vo.PageResult;
import com.mail.server.common.R;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Service;

/**
 * @author yan
 * @date 2022/06/22 14:04
 **/
@Service
public class SmsFlashPromotionService {
    @DubboReference
    private SmsFlashPromotionApi smsFlashPromotionApi;

    public R create(SmsFlashPromotion smsFlashPromotion) {
        smsFlashPromotionApi.create(smsFlashPromotion);
        return R.success(null);
    }

    public R delete(Long id) {
        smsFlashPromotionApi.delete(id);
        return R.success(null);
    }

    public R list(String keyword, Long pageNum, Long pageSize) {
        Page<SmsFlashPromotion> page = smsFlashPromotionApi.selectList(keyword, pageNum, pageSize);
        PageResult pageResult = new PageResult(pageNum, pageSize, page.getTotal(), page.getRecords());
        return R.success(pageResult);

    }

    public R updateStatus(Long id, Integer status) {
        smsFlashPromotionApi.updateStatus(id,status);
        return R.success(null);
    }

    public R updateFlashPromotion(Long id, SmsFlashPromotion promotion) {
        smsFlashPromotionApi.updateFlashPromotion(id,promotion);
        return R.success(null);
    }

    public R getFlashPromotion(Long id) {
        SmsFlashPromotion promotion=smsFlashPromotionApi.getFlashPromotion(id);
        return R.success(promotion);
    }
}
